//
//  AIGirlDetainmentView.swift
//  AIGirl
//
//  Created by Rae on 2024/1/2.
//

import UIKit
import SwiftEntryKit

class AIGirlDetainmentView: UIView, AnimationProtocol, AnimationDelegate {

    func animationContainerViewSize() -> CGSize {
        CGSize(width: .screenWidth , height: 345.0)
    }
    
    func animationContainerViewStyle() -> AnimationViewStyle {
        .center
    }
    
    func animationContainerScreenInteraction() -> EKAttributes.UserInteraction {
        .init()
    }
    
    private lazy var contentButton = c_make_ex(UIButton.self)
        .image("AIGirl_Discover_Detail_detainment").end()
    private lazy var closeButton = c_make_ex(UIButton.self)
        .image("AIGirl_Discover_Detail_close").end()
    var purchaseClosure: (() -> Void)?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = .clear
        subviews{
            contentButton
            closeButton
        }
        
        contentButton.leading(15).trailing(15).top(0).height(275.0)
        closeButton.size(45).bottom(0).centerHorizontally()
        
        closeButton.addTarget(self, action: #selector(clickCloseButton), for: .touchUpInside)
        contentButton.addTarget(self, action: #selector(clickBuyButton), for: .touchUpInside)
    }
    
    @objc private func clickBuyButton(){
        animation.animation(dismiss: self){
            self.purchaseClosure?()
        }
    }
    
    @objc private func clickCloseButton(){
        animation.animation(dismiss: self)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

class AIGirlBuySuccessView: UIView, AnimationProtocol, AnimationDelegate {

    func animationContainerViewSize() -> CGSize {
        CGSize(width: .screenWidth , height: 330.0)
    }
    
    func animationContainerViewStyle() -> AnimationViewStyle {
        .center
    }
    
    func animationContainerScreenInteraction() -> EKAttributes.UserInteraction {
        .init()
    }
    
    private lazy var contentButton = c_make_ex(UIButton.self)
        .image("AIGirl_Discover_Detail_success").end()
    private lazy var closeButton = c_make_ex(UIButton.self)
        .image("AIGirl_Discover_Detail_close").end()
    var setBgClosure: ((_ girlId: Int, _ photoId: Int) -> Void)?
    var model: AIGirlItemModel?
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = .clear
        subviews{
            contentButton
            closeButton
        }
        
        contentButton.leading(0).trailing(0).top(0).height(250.0)
        closeButton.size(45).centerHorizontally()
        closeButton.Top == contentButton.Bottom + 25

        closeButton.addTarget(self, action: #selector(clickCloseButton), for: .touchUpInside)
        contentButton.addTarget(self, action: #selector(clickBuyButton), for: .touchUpInside)
    }
    
    @objc private func clickBuyButton(){
        animation.animation(dismiss: self){
            guard let md = self.model else { return }
            let girlId = UserDefaultsManager.getInt(forKey: .girlId)
//            let modelId = UserDefaultsManager.getInt(forKey: .modelId)
            self.setBgClosure?(girlId,md.modelId)
        }
    }
    
    @objc private func clickCloseButton(){
        animation.animation(dismiss: self)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
